using Microsoft.EntityFrameworkCore;
using Zhaoxi.Zhihu.Core.AppUserAggregate.Entites;
using Zhaoxi.Zhihu.Core.AppUserAggregate.Specification;

using Zhaoxi.Zhihu.SharedKerel.Domain;
using Zhaoxi.Zhihu.SharedKerel.Repositoy;

namespace Zhaoxi.Zhihu.Infrastructure.Repositories;

public class EfRepository<T>(AppDbContext dbContext):EfReadRepository<T>(dbContext),IRepository<T>
where T:class,IAggregateRoot,IEntity<int>
{
    private readonly AppDbContext _dbContext=dbContext;
    public T Add(T entity)
    {
        dbContext.Set<T>().Add(entity);
        return entity;
    }

    public void Update(T entity)
    {
        dbContext.Set<T>().Update(entity);
    }

    public void Delete(T entity)
    {
        dbContext.Set<T>().Remove(entity);
    }

    public async Task<int> SaveChangesAsync(CancellationToken cancellationToken = default)
    {
        return  await dbContext.SaveChangesAsync(cancellationToken);
    }

    public Task<AppUser> GetSingleOrDefaultAsync(FollowQuestionByIdSpec spec, CancellationToken cancellationToken)
    {
        throw new NotImplementedException();
    }
}